#include "soft_set.h"
#include "ui_soft_set.h"

soft_set::soft_set(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::soft_set)
{
    ui->setupUi(this);
    this->setWindowTitle("软件设置");
    this->setStyleSheet("background-color: #E2EEF7");
    this->setMaximumSize(this->width(), this->height());
    this->setMinimumSize(this->width(), this->height());

    setAttribute(Qt::WA_QuitOnClose,false);

    ui->pushButton_change->setStyleSheet("color: white; background-color: #55AAFF");
    ui->pushButton_save->setStyleSheet("color: white; background-color: #55AAFF");
    connect(ui->pushButton_change, SIGNAL(clicked(bool)), this, SLOT(change_path()));
    connect(ui->pushButton_save, SIGNAL(clicked(bool)), this, SLOT(save_all()));
}

void soft_set::display_setting(){
    file_path = new QFile("locate.txt");
    file_path->open(QIODevice::ReadWrite);
    QTextStream stream_path(file_path);
    QString path;
    stream_path >> path;
    ui->label_path->setText(path);


    file_com = new QFile("com.txt");
    file_com->open(QIODevice::ReadWrite);
    QTextStream stream_com(file_com);
    QString com;
    stream_com >> com;
    ui->lineEdit->setText(com);

    file_com->close();
    file_path->close();

    this->show();
}


void soft_set::change_path(){
    QString path = QFileDialog::getExistingDirectory(this, "请选择路径", "C:\\");
    ui->label_path->setText(path);
}

void soft_set::save_all(){
    file_path = new QFile("locate.txt");
    file_path->open(QIODevice::ReadWrite | QIODevice::Truncate);
    QTextStream stream_path(file_path);
    stream_path << ui->label_path->text();


    file_com = new QFile("com.txt");
    file_com->open(QIODevice::ReadWrite | QIODevice::Truncate);
    QTextStream stream_com(file_com);
    stream_com << ui->lineEdit->text();

    QMessageBox::information(this, "提示", "保存成功", "确认", "取消");

    file_com->close();
    file_path->close();
    this->close();
}


soft_set::~soft_set()
{
    delete ui;
}
